#include "graphicsmodel.h"

bool GraphicsModel::LoadFromFile(char* filename)
{
	fstream file;

	file.open(filename);
	if(file.fail())
	{
		return false;
	}

	file >> indexCount;
	file >> vertexCount;

	Vertices = new VertexType[vertexCount];
	Indices = new unsigned long[indexCount];
	
	for(int i = 0; i < vertexCount;i++)
	{
		file >> Vertices[i].position.x >> Vertices[i].position.y >> Vertices[i].position.z;
		file >> Vertices[i].color.x >> Vertices[i].color.y >> Vertices[i].color.z >> Vertices[i].color.w;
	}

	for(int i = 0; i < indexCount;i++)
	{
		file >> Indices[i];
	}
	file.close();
	//unsigned long IndexCheck = Indices[0];


	return true;
}

GraphicsModel::GraphicsModel()
{
	vertexCount = 0;
	indexCount = 0;
}

GraphicsModel::~GraphicsModel()
{
	
}

void GraphicsModel::Rotate(float degree)
{
	float radians = degree*(D3DX_PI/180);
	for(int i = 0; i < vertexCount; i++)
	{
		Vertices->position.x = cos(radians)*Vertices->position.x - sin(radians)*Vertices->position.y;
		Vertices->position.y = sin(radians)*Vertices->position.x; + cos(radians)*Vertices->position.y;
	}
	return;
}

void GraphicsModel::Shutdown()
{
	delete [] Vertices;
	Vertices = 0;

	delete [] Indices;
	Indices = 0;
}